package com.zhousb.file_retrieval_server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itextpdf.text.DocumentException;
import com.zhousb.file_retrieval_server.common.PageRequest;
import com.zhousb.file_retrieval_server.common.R;
import com.zhousb.file_retrieval_server.common.ResponseResult;
import com.zhousb.file_retrieval_server.domain.bo.UploadBo;
import com.zhousb.file_retrieval_server.domain.so.ContractPageSo;
import com.zhousb.file_retrieval_server.service.ContractService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhouShenBin
 * @date 2024/9/24 16:14
 * @description
 */
@RestController
@RequestMapping("/contract")
public class ContractController {

    @Resource
    private ContractService contractService;

    @PostMapping("/page")
    public ResponseResult page(@RequestBody PageRequest<ContractPageSo> so) {
        return R.success(contractService.page(new Page<>(so.getCurrent(),so.getSize()),so.getQuery()));
    }

    @PostMapping("/upload")
    public ResponseResult<Boolean> upload(@RequestBody UploadBo bo) throws DocumentException, FileNotFoundException {
        return R.success(contractService.upload(bo));
    }

    @PostMapping("/uploadFile")
    public ResponseResult uploadFile(MultipartFile file) throws IOException {
        return R.success(contractService.uploadFile(file));
    }
}
